package com.liao.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liao.common.entity.product.ProductImgsEntity;
import com.liao.common.utils.PageUtils;
import com.liao.common.utils.Query;
import com.liao.product.dao.ProductImgsDao;
import com.liao.product.service.ProductImgsService;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("productImgsService")
public class ProductImgsServiceImpl extends ServiceImpl<ProductImgsDao, ProductImgsEntity> implements ProductImgsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProductImgsEntity> page = this.page(
                new Query<ProductImgsEntity>().getPage(params),
                new QueryWrapper<ProductImgsEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public boolean save(ProductImgsEntity entity) {
        QueryWrapper<ProductImgsEntity> productImgsEntityQueryWrapper = new QueryWrapper<>();
        productImgsEntityQueryWrapper.eq("spu_id", entity.getSpuId());
        productImgsEntityQueryWrapper.eq("img_type", entity.getImgType());

        int count = count(productImgsEntityQueryWrapper);
        if (count != 0) {
            throw new RuntimeException("图片集已存在");
        }
        return super.save(entity);
    }

//    @Override
//    public boolean updateById(ProductImgsEntity entity) {
//
//
//        return super.updateById(entity);
//    }
}